﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UMLTouch.Core.Commands;
using System.Windows.Input;
using UMLTouch.Core.ViewModel;

namespace UMLTouch.UI.Start.ViewModels
{
    public abstract class PopupViewModel : ViewModelBase
    {
        public event EventHandler PopupCanceled;
        public event EventHandler PopupValidated;
        public event EventHandler PopupClosed;

        bool _visible;

        public bool Visible
        {
            get { return _visible; }
            set
            {
                if (_visible == value)
                    return;
                _visible = value;
                this.RaisePropertyChanged("Visible");
            }
        }

        ICommand _requestClose;

        public ICommand RequestClose
        {
            get { return _requestClose; }
            set {
                if (_requestClose == value)
                    return;
                _requestClose = value;
                this.RaisePropertyChanged("RequestClose");
            }
        }

        ICommand _requestCancel;

        public ICommand RequestCancel
        {
            get { return _requestCancel; }
            set { _requestCancel = value; }
        }

        ICommand _requestValidate;

        public ICommand RequestValidate
        {
            get { return _requestValidate; }
            set { _requestValidate = value; }
        }


        public void Show()
        {
            Visible = true;
        }
        public void Hide()
        {
            Visible = false;

            
        }


        protected virtual void RaiseCloseEvent()
        {
            Hide();
            if (PopupClosed != null)
            {
                PopupClosed(this, new EventArgs());
            }

        }
        protected virtual void RaisePopupCanceledEvent()
        {
            if (PopupCanceled != null)
            {
                PopupCanceled(this, new EventArgs());
            }
            RaiseCloseEvent();
        }
        protected virtual void RaisePopupValidatedEvent()
        {
            if (PopupValidated != null)
            {
                PopupValidated(this, new EventArgs());
            }
            RaiseCloseEvent();
        }

        public PopupViewModel()
        {
            _requestClose = new RelayCommand(o=>RaiseCloseEvent());
            _requestCancel = new RelayCommand(o => RaisePopupCanceledEvent());
            _requestValidate = new RelayCommand(o => RaisePopupValidatedEvent());
        }

       

       
    }
}
